package com.ruoyi.project.business.controller;

import cn.mabach.business.dto.FlashPromotionSessionDetail;
import cn.mabach.business.entity.FlashPromotionSessionEntity;
import cn.mabach.result.PageResult;
import cn.mabach.result.RS;
import com.ruoyi.project.business.feign.FlashPromotionSessionServiceFeign;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 限时购场次表
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2019-12-31 21:38:07
 */
@RestController
@RequestMapping("/flashSession")
public class FlashPromotionSessionController {
    @Autowired
    private FlashPromotionSessionServiceFeign flashPromotionSessionService;




    /**
        * 分页列表
        */
//    @GetMapping(value = "/list")
//    @PreAuthorize("@ss.hasPermi('sms:flashSession:read')")
//    public RS<PageResult<FlashPromotionSessionEntity>> getList(@RequestParam(value = "keyword", required = false) String keyword,
//                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
//                                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
//
//        RS<PageResult<FlashPromotionSessionEntity>> pageResultRS = flashPromotionSessionService.queryPage(keyword, pageNum, pageSize);
//
//        return pageResultRS;
//    }



    /**
     * 根据ID获取信息
     */

    @GetMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPermi('sms:flashSession:read')")
    public RS<FlashPromotionSessionEntity> getItem(@PathVariable("id") Long id) {
        return flashPromotionSessionService.getByIdE(id);
    }





    /**
     * 根据id保存
     */
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('sms:flashSession:create')")
    public RS create(@RequestBody FlashPromotionSessionEntity flashPromotionSessionEntity) {

        RS rs = flashPromotionSessionService.saveE(flashPromotionSessionEntity);

        return rs;
    }



    /**
     * 根据id修改
     */
    @PostMapping(value = "/update/{id}")
    @PreAuthorize("@ss.hasPermi('sms:flashSession:update')")
    public RS update(@PathVariable("id") Long id,
                     @Validated @RequestBody FlashPromotionSessionEntity entity,
                     BindingResult result) {
        entity.setId(id);
        RS rs = flashPromotionSessionService.updateByIdE(entity);

        return rs;
    }

    /**
       * 根据id集合删除
       */
    @PostMapping(value = "/delete")
    @PreAuthorize("@ss.hasPermi('sms:flashSession:delete')")
    public RS deleteBatch(@RequestParam("ids") List<Long> ids) {
        RS rs = flashPromotionSessionService.removeByIdsE(ids);
        return rs;
    }

    /**
         * 根据id删除
         */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('sms:flashSession:delete')")
    public RS removeByIdE(@PathVariable Long id) {

        return flashPromotionSessionService.removeByIdE(id);

    }


    @RequestMapping(value = "/update/status/{id}", method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('sms:flashSession:update')")
    public RS updateStatus(@PathVariable Long id, @RequestParam("status") Integer status) {
       return flashPromotionSessionService.updateStatus(id,status);
    }


    /**
     * 获取全部场次
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @PreAuthorize("@ss.hasPermi('sms:flashSession:read')")
    public RS<List<FlashPromotionSessionEntity>> listAll() {
       return flashPromotionSessionService.listAll();
    }

    /**
     * 获取全部可选场次及其数量
     */
    @RequestMapping(value = "/selectList", method = RequestMethod.GET)
    @PreAuthorize("@ss.hasPermi('sms:flashSession:read')")
    public RS<List<FlashPromotionSessionDetail>> selectList(@RequestParam("flashPromotionId") Long flashPromotionId) {
       return flashPromotionSessionService.selectList(flashPromotionId);
    }
}

